﻿using System;
using System.Drawing;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using System.Windows.Media.Imaging;

namespace YArchitech.Public
{
	public class VerticalMenuCommandInfos
	{
		public string CmdName { get; set; }

		public string CmdText { get; set; }

		public string DllName { get; set; }

		public string ClassName { get; set; }

		public string ImageName { get; set; }

		public string Tooltip { get; set; }

		public string PanelName { get; set; }

		public VerticalMenuCommandInfos()
		{
		}

		public VerticalMenuCommandInfos(string cmdName, string cmdText, string dllName, string className, string imageName, string tooltip, string panelName)
		{
			this.CmdName = cmdName;
			this.CmdText = cmdText;
			this.DllName = dllName;
			this.ClassName = className;
			this.ImageName = imageName;
			this.Tooltip = tooltip;
			this.PanelName = panelName;
		}

		public VerticalMenuCommandInfos(VerticalMenuCommandInfos infos)
		{
			this.CmdName = infos.CmdName;
			this.CmdText = infos.CmdText;
			this.DllName = infos.DllName;
			this.ClassName = infos.ClassName;
			this.ImageName = infos.ImageName;
			this.Tooltip = infos.Tooltip;
			this.PanelName = infos.PanelName;
		}

		public static System.Windows.Controls.Image GetImageByName(string imageFillName)
		{
			System.Windows.Controls.Image image = new System.Windows.Controls.Image();
			Bitmap bmp = new Bitmap(imageFillName);
			image.Source = VerticalMenuCommandInfos.ChangeBitmapToBitmapSource(bmp);
			image.HorizontalAlignment = HorizontalAlignment.Left;
			image.Margin = new Thickness(0.0, 5.0, 0.0, 0.0);
			return image;
		}

		private static BitmapSource ChangeBitmapToBitmapSource(Bitmap bmp)
		{
			BitmapSource result;
			try
			{
				result = Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
			}
			catch
			{
				result = null;
			}
			return result;
		}
	}
}
